﻿using Domain.Roles.Entities;
using Domain.Roles.ValueObjects;
using Domain.UserRole.Entities;
using Infrastructure.Data.ValueConverter;
using Microsoft.EntityFrameworkCore;

namespace Infrastructure.Data.Contexts
{
    public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
    {
        internal DbSet<Role> Roles { get; set; }

        //internal DbSet<UserRole> UserRoles { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //直接配置
            modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);

        }

        protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
        {
            configurationBuilder.Properties<RoleName>()
                .HaveConversion<RoleNameConverter>();
        }
    }
}
